package com.woniu.cms.goods.core.controller;


import com.woniu.cms.goods.core.dto.PaybackDto;
import com.woniu.cms.goods.core.entity.GoodsOutbill;
import com.woniu.cms.goods.core.entity.GoodsOutbillMaterial;
import com.woniu.cms.goods.core.entity.GoodsPayback;
import com.woniu.cms.goods.core.entity.GoodsPaybackMaterial;
import com.woniu.cms.goods.core.service.IGoodsGetbillMaterialService;
import com.woniu.cms.goods.core.service.IGoodsPaybackMaterialService;
import com.woniu.cms.goods.core.service.IGoodsPaybackService;
import com.woniu.common.api.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 回缴单表 前端控制器
 * </p>
 *
 * @author romantic sheep
 * @since 2022-09-19
 */
@RestController
@Api(tags = "缴料单模块")
@RequestMapping("/goods-payback")
public class GoodsPaybackController {

    @Autowired
    private IGoodsGetbillMaterialService getbillMaterialService;
    @Autowired
    private IGoodsPaybackMaterialService paybackMaterialService;
    @Autowired
    private IGoodsPaybackService paybackService;

    /*
     * 新增缴料单
     * @payback，缴料单主表信息
     * @list，缴料单材料明细页材料列表
     * */
    @PostMapping("insert")
    @ApiOperation("新增缴料单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "paybackDto",value = "缴料单主表信息,缴料单材料明细页材料列表")
    })
    public Result addPayback(@RequestBody PaybackDto paybackDto){
        GoodsPayback payback = paybackDto.getPayback();
        List<GoodsPaybackMaterial> list = paybackDto.getList();
        Result result=paybackService.addPayback(payback,list);
        return result;
    }
    /*
     * 删除缴料单
     * @id，缴料单主表id
     * @status，提交状态（0-未提交，1-已提交（审批中），2-审批通过，3-已驳回）
     * */
    @ApiOperation("删除缴料单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "缴料单主表id"),
            @ApiImplicitParam(name = "status",value = "提交状态（0-未提交，1-已提交（审批中），2-审批通过，3-已驳回）")
    })
    @DeleteMapping("delete")
    public Result deletePayback(Integer id,Integer status){
        Result result=paybackService.deletePayback(id,status);
        return result;
    }

    /*
     * 修改缴料单
     * @payback，缴料单主表信息
     * @list，缴料单材料明细页材料列表
     * */
    @ApiOperation("修改缴料单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "paybackDto",value = "缴料单主表信息,缴料单材料明细页材料列表")
    })
    @PutMapping("update")
    public Result updatePayback(@RequestBody PaybackDto paybackDto){
        GoodsPayback payback = paybackDto.getPayback();
        List<GoodsPaybackMaterial> list = paybackDto.getList();
        Result result=paybackService.updatePayback(payback,list);
        return result;
    }
    /*
     * 提交缴料单
     * @outbill，缴料单主表信息
     * @list，缴料单材料明细页材料列表
     * */
    @ApiOperation("提交缴料单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "paybackDto",value = "缴料单主表信息,缴料单材料明细页材料列表")
    })
    @PutMapping("commit")
    public Result commitPayback(@RequestBody PaybackDto paybackDto){
        GoodsPayback payback = paybackDto.getPayback();
        List<GoodsPaybackMaterial> list = paybackDto.getList();
        Result result=paybackService.commitPayback(payback,list);
        return result;
    }
}

